import {failToast, hideLoading, showLoading, successToast, titleLoading} from "@/_framework/services/Taro";
import {add, remove, submit, update} from "@/_framework/services/Data";

export const handleAdd = async (url, params) => {
    titleLoading('正在添加')
    const {data, code, msg, success} = await add(url, params);
    hideLoading()
    if (success) {
        successToast('添加成功')
        return data;
    } else {
        failToast(`添加失败,错误码${code}：${msg}`)
    }
};

export const handleUpdate = async (url, params) => {
    titleLoading('正在更新')
    const {data, code, msg, success} = await update(url, params);
    hideLoading()
    if (success) {
        successToast('更新成功')
        return data;
    } else {
        failToast(`更新失败,错误码${code}：${msg}`)
    }
};

export const handleRemove = async (url, id) => {
    titleLoading('正在删除')
    const {data, code, msg, success} = await remove(url, id);
    hideLoading()
    if (success) {
        successToast('删除成功')
        return data;
    } else {
        failToast(`删除失败,错误码${code}：${msg}`)
    }
};

export const handleSubmit = async (url, params) => {
    titleLoading('正在提交')
    const {data, code, msg, success} = await submit(url, params);
    hideLoading()
    if (success) {
        successToast('提交成功')
        return data;
    } else {
        failToast(`提交失败,错误码${code}：${msg}`)
    }
};